// 引入创建store的仓库
import { defineStore } from "pinia";
import { reqUserInfo, reqMemberData, reqSkillLevel } from '../api/center/index'
// 引入moment
// import moment from 'moment'
let access_token = '93b69bf1-9a53-4639-8866-baa988967d23'
// 创建个人中心的仓库
let useCenterStore = defineStore('center', {
    // 数据的地方
    state: (): any => ({
        // 个人信息的数据
        userInfo: {},
        // 技能水平
        groupType: '',
        // 会员信息
        memberData: {},
        // 技能水平的信息
        skillLevel: [],
        token:localStorage.getItem('token')||''
    }),
    // 计算属性的地方
    getters: {

        followCount: (state) => {
            return (state.userInfo.statisticsBackup || {}).followCount
        },
        fansCount: (state) => {
            return (state.userInfo.statisticsBackup || {}).fansCount
        },
        webUrl:(state)=>{
            return (state.userInfo.moreBackup || {}).webUrl
        },  

        avocation(state) {
            return state.userInfo.avocation;

        }
    },
    // 方法
    actions: {
        // 获取用户信息的请求
        async getUserInfo() {
            try {
                let result = await reqUserInfo()
                console.log(result);
                this.userInfo = result
                this.groupType = result.channel.groupType
                let token = '1234325462fsfa'
                this.token = token
                localStorage.setItem('token',token)
            } catch (error) {
                return error
            }
        },
        // 获取技能水平的数据
        async getSkillLevel(groupType: any) {
            try {
                let result = await reqSkillLevel(groupType)
                console.log(result);
                this.skillLevel = result
            } catch (error) {

            }

        }

    },

})

// 暴露仓库
export default useCenterStore